package show.lmm.demo.springboot_aot.controller;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import show.lmm.demo.springboot_aot.util.FileUtils;
import show.lmm.demo.springboot_aot.view.request.GetResourceRequest;
import show.lmm.demo.springboot_aot.view.response.GetResourceResponse;

@RequestMapping("/")
@RestController
public class IndexController {

    @GetMapping("/get_resource")
    public Mono<GetResourceResponse> getResource(@Validated GetResourceRequest info) {
        String resource;
        if (info.getTypeId() == 1) {
            resource = FileUtils.readAllText(this.getClass().getResourceAsStream("/config/demo.txt"));
        } else {
            resource = FileUtils.readAllText(this.getClass().getResourceAsStream("/config/demo2.txt"));
        }
        return Mono.just(new GetResourceResponse(resource));
    }
}
